/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-09-11
 * Time: 11:32
 */
public class longest_Ones {
    public int longestOnes(int[] nums, int k) {
        int flag=0;
        int len=0;;
        for (int right = 0,left=0; right < nums.length; right++) {
            if (nums[right]==0){
                flag++;
            }
            while (flag>k){
                if (nums[left]==0){
                    flag--;
                }
                left++;
            }
            len=Math.max(len,right-left+1);
        }
        return len;
    }
}
